Improve output of userdata, handling__tostring
and NULL
#45
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR includes 2 commits:
The first one includes evaluation of
__tostring
for userdata values. This should be safe because__tostring
of userdata is unlikely to recurse intoinspect
. A test is included.The second one adds a special case for NULL userdata.
When interpreting userdata values using 'inspect', the numeric identifiers
are useful to match identify of pointers (comparing the low counters
like
<userdata 3> is easier than reading long pointers like
userdata: 0x749abc39efa29`).However, the
NULL
pointer is enough of a special case that it isimportant to know when one of those numbered pointers happens to
be
NULL
. When one is dealing with things like JSON parsers, wherethe only usual userdata is
cjson.null
, one gets accostumed overtime to interpret
<userdata 1>
to meanNULL
. This is not obvious,however, and a seasoned user will trip up the day another userdata
is used in the same table and
NULL
is now<userdata 2>
.Adding a test for this would require compiling and loading a C extension, such as
lua-cjson
. I can do so if desired.